﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OutSourceLender.aspx.cs" Inherits="CRMWeb.Pages.Admin.OutSourceLender" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>OutSource Lender</title>
</head>
<body>
    <table id="dgOutsrclender" title="OutSource Lender" style="width: 600%; height: 370px"
          toolbar="#toolbarOutSourceLender" pagination="true" data-options="pageSize:10,pageList: [10,20,30,50]" rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="LenderID" width="100px" align="center">Lender ID</th>
                <th field="OutSourceLender" width="500px" align="center">OutSource Lender</th>
            </tr>
        </thead>
    </table>
    <div id="toolbarOutSourceLender">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newOutSourceLender()">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editOutSourceLender()">Edit</a>
        <a id="lnkDelete" href="javascript:void(0)" class="easyui-linkbutton" onclick="openDelPopup()" plain="true" iconcls="icon-remove" title="Delete Client">Delete</a>
    </div>
    <div id="dlgOutsrclender" class="easyui-dialog" style="width: 350px; height: 220px; padding: 10px 20px"
        closed="true" buttons="#dlg-buttons">
        <div class="ftitle">OutSource Lender Information</div>
        <form id="fmOutsrcLender" method="post" novalidate>
            <div class="fitem">
                <label style="width: 130px;">OutSource Lender:</label>
                <input id="txtOutSourceLender" style="width: 292px;" class="easyui-validatebox" required="true" />
                <input id="hdnLenderID" value="" style="display: none" />
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlgOutsrclender').dialog('close')" style="float: left">Cancel</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveOutSourceLender()">Save</a>
    </div>
   
    <script type="text/javascript">
      
        var url;
        function newOutSourceLender() {
            $('#dlgOutsrclender').dialog('open').dialog('setTitle', 'New OutSource Lender');
            $('#fmOutsrcLender').form('clear');
            $('#txtOutSourceLender').val('');
            $('#hdnLenderID').val('');
            url = '/WebServices/OutSourceLender/OutSourceLenderAdd';
        }
        window.onresize = function () {
            $('#dgOutsrclender').datagrid('resize', {
                width: window.innerWidth,
                height: window.innerHeight
            });
        }
        function editOutSourceLender() {
            var row = $('#dgOutsrclender').datagrid('getSelected');
            if (row) {
                $('#dlgOutsrclender').dialog('open').dialog('setTitle', 'Edit OutSource Lender');
                $('#fmOutsrcLender').form('load', row);
                $('#txtOutSourceLender').val(row.OutSourceLender);
                $('#hdnLenderID').val(row.LenderID);
                url = '/WebServices/OutSourceLender/OutSourceLenderEdit?LenderID=' + row.LenderID;
            }
        }

        function openDelPopup()
        {
            var row = $('#dgOutsrclender').datagrid('getSelected');
            if (row)
            {
                $('#dlgDelOutsrcLender').dialog('open');
                $('#headertext').html("Are you sure want to delete this OutSource Lender?");
                $('#dlgDelconfirm').dialog('open');
                $('#btnDelete').bind("click", function () {
                    deleteOutSourceLender();
                });
            }
        }
        //Resize datagrid:
        window.onresize = function () {
            $('#dgOutsrclender').datagrid('resize', {
                width: window.innerWidth - 165,
                height: window.innerHeight - 40
            });
        }
        function deleteOutSourceLender() {
            var row = $('#dgOutsrclender').datagrid('getSelected');
            if (row) {
                $.ajax({
                    url: '/WebServices/OutSourceLender.ashx',
                    type: 'POST',
                    data: {
                        method: 'OutSourceLenderDelete',
                        args: { LenderID: row.LenderID }
                    },
                    success: function (data) {
                        $('#dgOutsrclender').datagrid('reload');
                        $('#dlgDelconfirm').dialog('close');
                    }
                });
            }
        }
        function saveOutSourceLender() {
            var strOutSourceLender = $('#txtOutSourceLender').val();
            var LenderID = $('#hdnLenderID').val();

            if (LenderID != '') {
                if (strOutSourceLender != '') {
                    $.ajax({
                        url: '/WebServices/OutSourceLender.ashx',
                        type: 'POST',
                        data: {
                            method: 'OutSourceLenderEdit',
                            args: { LenderID: LenderID, OutSourceLender: strOutSourceLender }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgOutsrclender').dialog('close');
                                $('#dgOutsrclender').datagrid('reload');
                            }
                            else {
                                alert('OutSourceLender already exist');
                            }
                        }
                    });
                }
            }
            else {
                if (strOutSourceLender != '') {
                    $.ajax({
                        url: '/WebServices/OutSourceLender.ashx',
                        type: 'POST',
                        data: {
                            method: 'OutSourceLenderAdd',
                            args: { OutSourceLender: strOutSourceLender }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgOutsrclender').dialog('close');
                                $('#dgOutsrclender').datagrid('reload');
                            }
                            else {
                                alert('OutSourceLender already exist.');
                            }
                        }
                    });
                }
            }
        }

        $(document).ready(function () {
            $('#dgOutsrclender').datagrid({
                url:'/WebServices/OutSourceLender.ashx?method=OutSourceLenderSelect',
                onDblClickRow: function (index, rowdata) {
                    editOutSourceLender();
                }
            });
        });

    </script>
</body>
</html>
